package com.zzc.keleoj.judge.codesandbox.impl;

import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.zzc.keleoj.exception.BusinessException;
import com.zzc.keleoj.judge.codesandbox.CodeSandBox;
import com.zzc.keleoj.judge.codesandbox.model.ExecuteCodeRequest;
import com.zzc.keleoj.judge.codesandbox.model.ExecuteCodeResponse;
import com.zzc.keleoj.model.dto.questionSubmit.JudgeInfo;
import com.zzc.keleoj.model.enums.JudgeInfoMessageEnum;
import com.zzc.keleoj.model.enums.QuestionSubmitStatusEnum;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

public class RemoteCodeSandBox implements CodeSandBox {
    @Override
    public ExecuteCodeResponse executeCode(ExecuteCodeRequest executeCodeRequest) {
        String url = "http://192.168.174.130:8080/executeCode";
        String json = JSONUtil.toJsonStr(executeCodeRequest);
        String responseStr = HttpUtil.createPost(url)
//                .header(AUTH_REQUEST_HEADER, AUTH_REQUEST_SECRET)
                .body(json)
                .execute()
                .body();
//        if (StringUtils.isBlank(responseStr)) {
//            throw new BusinessException(ErrorCode.API_REQUEST_ERROR, "executeCode remoteSandbox error, message = " + responseStr);
//        }
        return JSONUtil.toBean(responseStr, ExecuteCodeResponse.class);
    }
}